<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="jquery.min.js"></script>
</head>

<body>
  用户名 ： <input type="text" name="" id="username"> <br> 密码： <input type="password" name="" id="pwd"> <br>
  <button id="login_btn">登录</button>
  <button id="reg_btn">注册</button>
  <script>
    $('#reg_btn').click(function() {
      var username = $('#username').val();
      var pwd = $('#pwd').val();
      $.ajax({
        url: '/user',
        data: {
          act: 'reg',
          username: username,
          pwd: pwd
        },
        type: 'get',
        dataType: 'json',
        success: function(json) {
          if (json.ok) {
            alert(json.msg);
          } else {
            alert(json.msg);
          }
        },
        error: function() {
          alert('通信失败');
        }
      })

    })

    $('#login_btn').click(function() {
      var username = $('#username').val();
      var pwd = $('#pwd').val();
      $.ajax({
        url: '/user',
        data: {
          act: 'login',
          username: username,
          pwd: pwd
        },
        type: 'get',
        dataType: 'json',
        success: function(json) {
          if (json.ok) {
            alert(json.msg);
          } else {
            alert(json.msg);
          }
        },
        error: function() {
          alert('通信失败');
        }
      })

    })
  </script>
</body>

</html>
